package com.tdf.webblog.handler;

import com.tdf.webblog.api.MySQLRemoteService;
import com.tdf.webblog.entity.AdminPermission;
import com.tdf.webblog.entity.AdminRole;
import com.tdf.webblog.result.Result;
import com.tdf.webblog.result.ResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class RoleHandler {

    @Autowired
    private MySQLRemoteService mySQLRemoteService;

    @GetMapping("/admin/role")
    public Result listRoles() {

        List<AdminRole> adminRoleList = mySQLRemoteService.listWithPermsAndMenusRemote();

        return ResultFactory.buildSuccessResult(adminRoleList);
    }

    @GetMapping("/admin/role/perm")
    public Result listPerms() {
        List<AdminPermission> adminPermissionList = mySQLRemoteService.listAdminPermissionRemote();
        return ResultFactory.buildSuccessResult(adminPermissionList);
    }
}
